-
Notifications
You must be signed in to change notification settings - Fork 1k
Add generic F401Rx variant #787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
As a first look, I really dislike move all pin_arduino.* files. Why not, for example add some guard:
and define or add a custom define :
Anyway, as I said, it's a first feeling and I have to go further. 😉 |
I'm willing to do whatever it takes for this PR to be merged 🙂 I'm busy tonight, but will continue working on this tomorrow. I'll see what I can do about the global pins_arduino.c/h files. But apart from this, what do you think? Positive? |
I guess removing Analog pins restrictions is really fine but as said moving the pin_arduino files is not the good way, see the diff numbers: +27,286
-0 while 99% are the same. |
I'm absolutely open to other ways of achieving this. However, I do need full control over :
|
As I said could be achieved easily with guard
This is already the case
Why this is hardware specific and not linked to a pin and already managed.
Same, with a guard or a define.
Static assert will be updated if needed and are present to avoid any issue with wrong definition. |
To prevent compiler warnings I had to change the numbers a bit on these macros. I defined ATEMP as I'll see if I can roll back the commit where all the pins_arduino.c/h files were added. |
Right and it is fine the compiler raise warning. This force to use cast if really needed. All you mentioned as a requirement is de facto linked how pins are managed. This simply means all have to be aligned with the new implementation. Which is normal. 😉 |
Sorry, but I'm having difficulties understanding what you mean here. Compiler warnings are there for a reason; the code isn't written the way it should. I always tries my best to get rid of warnings, because it "pollutes" the compiler output. IMO the core files should not generate warnings at all. This way, if the users see some red text in the output window, it is not caused by the core files, but rather the user program or included libraries. What I can do however is to just return (p) if the pin isn't correct. this is what's originally done anyways, and does not generate any warnings. The analogInputToDigitalPin is rarely used by user programs anyways; It's mainly used within the core files.
Hmm. I don't understand everything here, but I assume you think the requirements I have for this are OK. Am I right? |
Well forgot that and focus only on the original requirement:
Yes and no. I just want to say that "your" requirements are all dependent and related to each other. |
@fpistm how about now? Now only minimal changes to the global pins_arduino.h file are done. It still works as it should, and does not affect any other variants. |
@MCUdude |
So what changes do I have to do in order tofix the Astyle formatting and hopefully get this merged? |
See details of the check you will see what goes wrong. About merge, I will have to review deeply and check all uses case. |
To be honest, I'm absolutely no git expert, at all, sorry about that. Would you like it to be one commit where I add the variant files, one commit where I add the new variant to the boards.txt and one commit where I change the global pins_arduino.h file? In that case I'll have to roll back everything and start clean. |
You do not need to be a git expert. Your PR should only contains 2 commits:
|
Thanks for the heads-up, hopefully, it's OK now. EDIT: No, I still had messed some formatting. It should be OK now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally,
Firmata is no more compatible with this implementation:
https://github.com/firmata/arduino/blob/1ccb2c00e2b28f4ce7486d645d14fee71810c9fd/Boards.h#L860
Some new commits. I've tried to add descriptive comments. |
Done! Anything else you'd like to be changed? |
In fact, I will split this PR in 2 parts:
|
Can you point out to me what exact commits/commit hashes you'd want me to remove/roll back? |
I would not have the variant addition in the same PR than the analog pin definitions rework. |
I would assume you'd mean all changes I've done to pins_arduino.h? Or just the AEND part of it? The reason why I did it this way is that the generic F401Rx pinout relies on the changes done to pins_arduino.h. I'm not trying to be rude or anything, but it has been pretty time consuming for me with everything that I've put into this PR. It would be great if you were more specific about what you want and what you don't want to be included when I first opened this PR. Anyways, I'm slowly learning from my mistakes, and hopefully, next time can just provide a clean PR without having to re-do commits again and again. Should be better for us both 😉 |
@fpistm would be great if you could reply to my previous post. Hopefully, I can finish this up today 👍 |
@MCUdude +27,286
-0 It is now better formed. 😉 All what I advised are described in the Contributing.md (best practice, commits rules, ...). Currently, my concerns is that the PR should be ONLY to add the generic F401Rx variant. So give me some time to do the job. 😉 |
This PR now only contains the generic variant, and not anything else. Do you want me to open a new PR where changes to pins_arduino.h are done or do you want to do this yourself to get it exactly how you want it to be? |
Thanks @MCUdude |
Great! I'm pretty sure Travis CI fails to compile this PR because it's missing the PR you're about to do that changed the behavior of pins_arduino.h. But apart from this, are you satisfied with the PR now? I assume you won't (and can't) merge this before pins_arduino.h is modified. |
At a first look, it seems OK but I will deeply review and test it later using the new PR I will submit. |
Required #800 |
@MCUdude Ex of pin definitions: #define PC13 0
#define PC14 1
#define PC15 2
#define PF0 3
#define PF1 4
#define PC0 5 // A0
#define PC1 6 // A1
#define PC2 7 // A2
#define PC3 8 // A3
#define PA0 9 // A4/USER_BTN
#define PA1 10 // A5
#define PA2 11 // A6
#define PA3 12 // A7
#define PF4 13
#define PF5 14
#define PA4 15 // A8
#define PA5 16 // A9
#define PA6 17 // A10
#define PA7 18 // A11
#define PC4 19 // A12
#define PC5 20 // A13
#define PB0 21 // A14
#define PB1 22 // A15 |
Well, the pinout has to be mapped in a specific way to support both analogRead(0) and analogRead(A0). That's just the nature of it. TBH a function like analogReadChannel(0) would be much more suitable, because it may be difficult to combine the Ax constant and the channel number What pinout is the code posted above from? I suggest that all analog pins are only available on pinouts that allow channel number and pin number to be combined, like in this pinout |
Disco_F030R8
Unfortunately, this will not be maintainable and hard to review. This have to be as generic as possible. |
It seems like for the Disco F030R8 the NUM_ANALOG_FIRST is defined as 50. This makes for a nice offset to prevent channel numbers and Ax constants to overlap. However, you can't expect analogRead(5) (or analogRead(PC0)) to work, because it will choose analog channel 5, not the channel attached to digital pin 5. The question really is, How can we make all analog pins available on as many targets as possible. To me, it's not as important if the what number/constant/macro the analogRead function takes, but it has to be consistent. What do you suggest? How can we achieve 16 analog inputs on the generic F401Rx pinout without having to re-map the digital pins to fit/match the analog ones? |
In your proposal, |
Looking forward to seeing what you're able to come up with. What's important for me is that we can keep this exact pin mapping and still be able to access all analog pins in some way. This should be a goal for this repository as well IMO 🙂 |
Unfortunately, I will not be able to find a way to support this. If So if you want the generic variant for F401Rx, you will have to reorder the pin number. // | ANALOG | USART | TWI | SPI | SPECIAL |
// |--------|-----------|----------|------------------------|-----------|
#define PA0 21 // | A0 | | | | |
#define PA1 22 // | A1 | | | | |
#define PA2 23 // | A2 | USART2_TX | | | |
#define PA3 24 // | A3 | USART2_RX | | | |
#define PA4 25 // | A4 | | | SPI1_SS, (SPI3_SS) | |
#define PA5 26 // | A5 | | | SPI1_SCK | |
#define PA6 27 // | A6 | | | SPI1_MISO | |
#define PA7 28 // | A7 | | | SPI1_MOSI | |
#define PA8 0 // | | | TWI3_SCL | | |
#define PA9 1 // | | USART1_TX | | | |
#define PA10 2 // | | USART1_RX | | | |
#define PA11 3 // | | USART6_TX | | | |
#define PA12 4 // | | USART6_RX | | | |
#define PA13 5 // | | | | | SWD_SWDIO |
#define PA14 6 // | | | | | SWD_SWCLK |
#define PA15 7 // | | | | SPI1_SS, (SPI3_SS) | |
// |--------|-----------|----------|------------------------|-----------|
#define PB0 29 // | A8 | | | | |
#define PB1 30 // | A9 | | | | |
#define PB2 8 // | | | | | BOOT1 |
#define PB3 9 // | | | TWI2_SDA | SPI1_SCK, (SPI3_SCK) | |
#define PB4 10 // | | | TWI3_SDA | SPI1_MISO, (SPI3_MISO) | |
#define PB5 11 // | | | | SPI1_MOSI, (SPI3_MOSI) | |
#define PB6 12 // | | USART1_TX | TWI1_SCL | | |
#define PB7 13 // | | USART1_RX | TWI1_SDA | | |
#define PB8 14 // | | | TWI1_SCL | | |
#define PB9 15 // | | | TWI1_SDA | SPI2_SS | |
#define PB10 16 // | | | TWI2_SCL | SPI2_SCK | |
#define PB12 17 // | | | | SPI2_SS | |
#define PB13 18 // | | | | SPI2_SCK | |
#define PB14 19 // | | | | SPI2_MISO | |
#define PB15 20 // | | | | SPI2_MOSI | |
// |--------|-----------|----------|------------------------|-----------|
#define PC0 31 // | A10 | | | | |
#define PC1 32 // | A11 | | | | |
#define PC2 33 // | A12 | | | SPI2_MISO | |
#define PC3 34 // | A13 | | | SPI2_MOSI | |
#define PC4 35 // | A14 | | | | |
#define PC5 36 // | A15 | | | | |
#define PC6 37 // | | USART6_TX | | | |
#define PC7 38 // | | USART6_RX | | | |
#define PC8 39 // | | | | | |
#define PC9 40 // | | | TWI3_SDA | | |
#define PC10 41 // | | | | SPI3_SCK | |
#define PC11 42 // | | | | SPI3_MISO | |
#define PC12 43 // | | | | SPI3_MOSI | |
#define PC13 44 // | | | | | |
#define PC14 45 // | | | | | OSC32_IN |
#define PC15 46 // | | | | | OSC32_OUT |
// |--------|-----------|----------|------------------------|-----------|
#define PD2 47 // | | | | | |
// |--------|-----------|----------|------------------------|-----------|
#define PH0 48 // | | | | | OSC_IN |
#define PH1 49 // | | | | | OSC_OUT |
// |--------|-----------|----------|------------------------|-----------| As for generic variant, user mainly use the |
How is this solved on the Disco_F030R8 today? I bet analogRead(Ax) == analogRead(x) == analogRead(PYn) wont work. Any my pinout has nothing to do with this. Why would it be a problem to modify the |
Currently, this works.
Because, it could not be applied to all possible pins mapping. Anyway, I've just found a way to have a new generic way to define analog pins and seems removed all drawback. |
I don't really see why
Tell me about it! Bottom line: what I eventually want to achieve with this pinout (and maybe more in the future) is that a user can Start Arduino IDE or VSCode/PlatformIO and just pick the STM32 that's needed for the job. No board, NO only the top of the line chip available, but all memory options. A little bit like what I've done with my various AVR cores. This is also super useful if you find a commercial product with an STM32 on that you's like to write your own FW to. |
I think you don't understand you can already do that... As I said for generic board user will use the PYn format and are not aware of which value it is in the background. So, I really do not understand your point about that as the pin mapping could easily be done like I do in a previous comment. While doing an analogread(PYn) works... |
This pinout style matches the physical pin style of the F401Rx family pretty well. It makes it easier when working with purposely designed hardware that is not based around a development board. This variant will first try to drive an external crystal. If not present, the MCU will automatically switch to its internal (but less accurate) oscillator instead. Resolves #784
OK. Fixed now |
The new way of handlig analog pins was introduced in #800 and makes 'uneven' analog pin positions easier to implement in a nice way. This is great for generic pinouts.
How about now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends on #800
@MCUdude is it possible for you to create also generic variant for F407VET/VGT? |
It's certainly is possible, but I'm not planning to use an F407 in a design at the moment. I also don't have any F407 hardware to test with. However, I do plan to add F401Cx, F411Rx, and F411Cx. |
This is my take on a new generic variant for the STM32F401Rx chip family. This pinout can easily be adapted to other variants in the future, and I'm planning to do this if this PR goes through.